package com.zmn.plat.business.impl.service.tariff.channel;

import java.util.Objects;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.zmn.common.utils.number.NumberUtil;
import com.zmn.plat.business.interfaces.service.tariff.channel.ChannelTariffBService;
import com.zmn.plat.model.entity.service.tariff.ServiceTariff;
import com.zmn.plat.services.interfaces.service.tariff.ServiceTariffService;

/**
 * @author tanbiao
 * @description
 * @since 2020/3/19 15:27
 * @modifier
 **/
@Service
public class ChannelTariffBServiceImpl implements ChannelTariffBService {
    private transient Logger logger = LoggerFactory.getLogger(ChannelTariffBServiceImpl.class);
    @Resource
    private ServiceTariffService faultTariffService;

    @Override
    public ServiceTariff getTariffIdByProductIdAndChannelIdAndBizTypeAndTariffType(Integer productId, Integer channelId, Integer keepType, Integer tariffType) {
        // 根据渠道ID和类型查询服务组组合
        if (NumberUtil.isPositiveInteger(channelId) || NumberUtil.isPositiveInteger(keepType) || NumberUtil.isPositiveInteger(tariffType)) {
            // 渠道配置的启用状态价格表
            ServiceTariff tariff = faultTariffService.findByChannelIdAndBizTypeAndTariffType(channelId, keepType, tariffType);
            if (Objects.nonNull(tariff)) {
                return tariff;
            }
            // 产品的价格默认价格表
            // 渠道配置的启用状态价格表
            tariff = faultTariffService.findDefaultTariffByProductIdAndBizTypeAndTariffType(productId, keepType, tariffType);
            if (Objects.nonNull(tariff)) {
                return tariff;
            }
        }
        return null;
    }
}
